package top.tan.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import top.tan.entity.Visitor;
import top.tan.repository.VisitorRepository;
import top.tan.service.VisitorService;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;

@RestController
public class VisitorController {

    @Autowired
    private VisitorService visitorService;

    @RequestMapping("/")
    public String index(HttpServletRequest request) {

        Visitor visitor = visitorService.save(request);

        return "<img src='https://tool.lu/netcard/'>";
//        return "I have been seen ip " + visitor.getIp() + " " + visitor.getTimes() + " times." + " first visitor time: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(visitor.getCreateTime()) + " location: " + visitor.getLocation();
    }

}
